<?php 

namespace app\supermanager\controller;
use think\Db;
/**
 * 订单管理
 */
class Order extends \think\Controller
{
	use \app\common\traits\controller\TraitController;
	const ORDER_OBLIGATION_STATUS = 100;//待付款
    const ORDER_STAYIN_STATUS = 101;//待入住
    const ORDER_REFUND_ON = 102;//退款中
    const ORDER_CANCEL_STATUS = 103;//取消订单
    const ORDER_CHECKIN_STATUS = 200;//入住中
    const ORDER_LEAVE_STATUS = 201;//已离开 
    const ORDER_REFUND_DEPOSIT_STATUS = 202;//返还押金中
    const ORDER_REFUND_FINISH = 203;//已完成的订单
	protected function init(){
		if (!model('Managers')->checkLogin()) {
            $this->redirect('@manager/login');
            exit;
        }
		$this->model = model('Orders');
		$this->list_route = url('/orders');
	}
	/**
	 * 待付款订单信息
	 */
	public function getIndexPay(){
		$query = input('get.');
		$order = $this->model->getOrders(array_merge($query,['status' => self::ORDER_OBLIGATION_STATUS]));
	    $order_w_p = count($order);
	    return view('order/index_pay',['order'=>$order,'order_w_p'=>$order_w_p]);
	}
	
	/**
	 * 待入住订单信息
	 */
	public function getIndexWaitIn(){
		$query = input('get.');
		$order = $this->model->getOrders(array_merge($query,['status' => self::ORDER_STAYIN_STATUS]));
	    $order_d_z = count($order);
	    return view('order/index_wait_in',['order'=>$order,'order_d_z'=>$order_d_z]);
	}
	
	/**
	 * 退款中的订单信息.........................................
	 */
	public function getRefundOn(){
		$query = input('get.');
		$order = $this->model->getOrders(array_merge($query,['status' => self::ORDER_REFUND_ON]));
	    $order_t_k = count($order);
	    return view('order/refund_on',['order'=>$order,'order_t_k'=>$order_t_k]);
	}
	
	/**
	 * 取消的订单信息
	 */
	public function getIndexCancel(){
		$query = input('get.');
		$order = $this->model->getOrders(array_merge($query,['status' => self::ORDER_CANCEL_STATUS]));
	    $order_q_x = count($order);
	    return view('order/index_cancel',['order'=>$order,'order_q_x'=>$order_q_x]);
	}
	
	/**
	 * 入住中订单信息
	 */
	public function getIndexIn(){
	    $query = input('get.');
		$order = $this->model->getOrders(array_merge($query,['status' => self::ORDER_CHECKIN_STATUS]));
	    $order_r_z = count($order);
	    return view('order/index_in',['order'=>$order,'order_r_z'=>$order_r_z]);
	}
	
	/**
	 * 已离开订单信息
	 */
	public function getLeaved(){
		$query = input('get.');
		$order = $this->model->getOrders(array_merge($query,['status' => self::ORDER_LEAVE_STATUS]));
	    $order_y_k = count($order);
	    return view('order/leaved',['order'=>$order,'order_y_k'=>$order_y_k]);
	}
	
	/**
	 * 返还押金中订单信息
	 */
	public function getRefundDeposit(){
		$query = input('get.');
		$order = $this->model->getOrders(array_merge($query,['status' => self::ORDER_REFUND_DEPOSIT_STATUS]));
	    $order_f_y = count($order);
	    return view('order/refund_deposit',['order'=>$order,'order_f_y'=>$order_f_y]);
	}
	
	/**
	 * 已完成订单信息
	 */
	public function getIndexComplete(){
		$query = input('get.');
		$order = $this->model->getOrders(array_merge($query,['status' => self::ORDER_REFUND_FINISH]));
	    $order_w_c = count($order);
	    return view('order/index_complete',['order'=>$order,'order_w_c'=>$order_w_c]);
	}
	
	/**
	 * 订单详情
	 */
	public function getRead(){
		$order = $this->model->getOrderInfo(input('get.id')); 
		$leave_car_date=strtotime($order['leave_car_date']);
        $take_car_date=strtotime($order['take_car_date']);
        $date=($leave_car_date-$take_car_date)/86400;
	    return view('order/read',['order' => $order,'date'=>$date]);
	} 
	 
}

 ?>